home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 576-600 / 592 / star / star.doc < prev    next >
Text File  |  1995-03-15  |  6KB  |  171 lines

  1.  
  2.  
  3.  
  4.                               STAR V1.0
  5.                               ---------
  6.  
  7.                             By Jason Lowe
  8.  
  9.                            (December 1991)
  10.  
  11.  
  12. PREFACE:
  13.  
  14. Completed:     December, 1991
  15. Language:      Aztec C and Lattice C.
  16. Programmer:    Jason Lowe
  17. Age:           18
  18. Computer:      Amiga 500
  19. Comments:      Works fine with both Aztec and Lattice.
  20.  
  21.  
  22.    Any questions, ideas, comments etc on anything to do with me or my code
  23. please write. My home address is
  24.  
  25.                            5 Collaroy Close  
  26.                            Chittaway Bay
  27.                            N.S.W 2259
  28.                            Australia.
  29.  
  30.  
  31.  
  32.    Star is not a stand alone graphics demonstration for the Amiga. It is a
  33. few C functions that can be accessed very easily by any C programmer. This
  34. program and its code is distributed as NO RIGHTS RESERVED. You may modify
  35. this program to fit your own needs, and use it where ever you wish. The
  36. following text file explains,
  37.  
  38.    (a) How the program actually draws stars.
  39.    (b) How to use these C functions in your own programs.
  40.    (c) Conclusion.
  41.  
  42.  
  43.  
  44.  
  45. (a) How the program actually draws stars.
  46.  
  47.    This program uses no fancy mathematics to draw its stars. The following
  48. is the basic idea behind drawing the stars. 
  49.    Firstly to demonstrate how star works, go and grab a pen and paper. On
  50. this piece of paper draw a reletively neat circle. On the circumference of
  51. this circle mark 8 points such that they are all equally spaced. Then
  52. number these points in a clockwise direction 1,2,3,4,5,6,7 and 8. Now we
  53. are ready to draw our star. 
  54.    Start at point 1 and count 3 points around the circle in a clockwise
  55. direction. You should have ended up at point 4. Now join these two points
  56. together. 
  57.    Now from point 4 do exactly the same thing. Count 3 points around the
  58. circle in a clockwise direction. You should have ended up at point 7. Now
  59. connect these two points. Repeat this process until you end up back at 
  60. point 1. As you can guess the whole process will start over again.
  61.    As you can see when you have finished you have a shape which looks
  62. something like a star. This is the process I have used in drawing my stars.
  63. Open the program STAR, which opens up a HIRES INTERLACED screen and draws
  64. stars randomly. If there is no code for any of the programs I have written,
  65. just write to me and I would be more than happy to send it to you.
  66.  
  67.  
  68.  
  69.  
  70. (b) How to use these C functions in your own programs.
  71.  
  72.    There are 3 functions which you use in your own program to create stars.
  73. These 3 functions work in a similar way to the way you drew a star on a piece
  74. of paper. The 3 functions that you use are,
  75.  
  76.                         i)   Init_Values
  77.                         ii)  Draw_Star
  78.                         iii) Free_Values
  79.  
  80.    Now I will use an example program to illustrate the use of each of these
  81. functions. 
  82.  
  83. LINE 1:     #include "star.h"
  84. LINE 2:     main()
  85. LINE 3:     {
  86. LINE 4:     int *values1;
  87.  
  88. LINE 5:     values1=Init_Values(50,8);
  89. LINE 6:     if(values1==0) exit(0);    /* Can't allocate memory for stars */
  90. LINE 7:     Draw_Star(rastport,values1,120,120,3);
  91. LINE 8:     Free_Values(values1);
  92. LINE 9:     }
  93.  
  94.  
  95.    Firstly you must include star.h in your porgram. You must also to
  96. remember to compile and link your program which your mathematical
  97. libraries, due to this program using floating point. (Only once).
  98.  
  99.    After you have included star.h you need to declare an integer pointer. In
  100. the example above I have declared values1 as an integer pointer. Then you
  101. must call the function Init_Values. If Init_Values has done its job
  102. correctly it will return a normal integer pointer, else if something went
  103. wrong it will return 0. You can call this function as many times as you
  104. wish. (Just remember to use different integer pointers).
  105.  
  106. Synopsis:      pointer=Init_Values(radius,points)
  107.  
  108. pointer:       pointer is an integer pointer that you declare yourself.
  109.                Returns 0 if something went wrong.
  110.  
  111. radius:        (int) This is the radius of the circle that your star is
  112.                going to be drawn in. (In pixels).
  113.  
  114. points:        (int) This is how many points the computer will calculate 
  115.                around the circle. 
  116.  
  117.    As you can remember from before you drew a circle of a given radius then
  118. calculated a certain number of points around it. This is what this function
  119. does. In the example above I have asked for 8 equally spaced points around
  120. a circle of radius 50 pixels. (Just like our example on paper). Now to get
  121. the computer to actually draw stars from these points we must call Draw_Star.
  122.  
  123. Synopsis:      Draw_Star(rastport,pointer,X,Y,count)
  124.  
  125. rastport:      (Struct Rastport *) This is a pointer to the rastport you
  126.                wish to draw the star in.
  127.  
  128. pointer:       (int *) This is the integer pointer that was returned by
  129.                Init_Values.    
  130.  
  131. X:             (int) This is the x co-ordinate of the center of the star.
  132.  
  133. Y:             (int) This is the y co-ordinate of the center of the star.
  134.  
  135. count:         (int) This is how many points you wish to jump at a time. In
  136.                the star you drew on paper, you used 3.
  137.  
  138.    In the example above I have selected to draw a star at location
  139. (120,120) and jump 3 points a time, just like in the example we drew on
  140. paper. You may also call this function as many times as you wish.
  141.  
  142.    Now once you have finished drawing stars, you must deallocate all memory
  143. allocated. You do this with the function Free_Values.
  144.  
  145. Synopsis:      Free_Values(pointer)
  146.  
  147. pointer:       (int *) This is the integer pointer that was returned by
  148.                Init_Values.    
  149.  
  150.  
  151.  
  152.    (c) Conclusion.
  153.  
  154.    This program can get rather tedious after a while, but never the less it
  155. would still look quite attractive in a larger demo you are writing. If you
  156. have the time why not try to write something similar to this and send it to
  157. me. I would be very interested to see it. I would also send you some of my
  158. latest ideas and code. 
  159.  
  160.    I have just recently joined Anders Bjerin's C club. It is a very
  161. worthwhile cause for all you buddying C programmers out there. If you
  162. haven't checked out Anders' C manual do so, and you'll learn heaps from it!
  163.  
  164.    In the mean time....
  165.  
  166.                      ***  HAPPY  PROGRAMMING  ***
  167.      
  168.  
  169.  
  170.  
  171.